<?php

namespace core\libs;

class log {
    // 配置信息
    protected static $log_conf = "";
    public function __construct() {
        self::$log_conf = \core\libs\config::get('app', 'LOG');
    }
    /**
	 * 写入日志
	 **/
    public static function insert($content = '', $path = '') {
        $path = self::$log_conf["path"] . $path . date('Ym') . '/';
        if(self::check_dir($path)) {
            $fp = @fopen($path . "log-". date('Ymd') .".txt", "a+");
		    fwrite($fp, $content . ' [' . date("Y/m/d H:i:s") . "]" . '['. get_real_ip() .']' . PHP_EOL);
            fclose($fp);
        }
    }
    /**
	 * 检查目录是否存在不存在自动创建
	 **/
	protected static function check_dir($dir) {
		if(!is_dir($dir)) {
			if(!mkdir($dir, 0777, true)) {
                throw new \Exception('创建文件夹失败：', $dir);
				return false;
			}
		}
		return true;
	}
}